package cn.ren.hai.base.controller;


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.ren.hai.base.service.ModuleService;
import cn.ren.hai.base.entity.Module;
import cn.ren.hai.core.entity.QueryPage;
import cn.ren.hai.core.entity.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.ren.hai.core.response.ResponseBean;

import java.io.Serializable;

/**
 * <p>
 * 导航  前端控制器
 * </p>
 *
 * @author wangdao
 * @since 2021-06-09
 */
@RestController
@RequestMapping("/api/base/module")
public class ModuleController {


    private final ModuleService moduleService;

    @Autowired
    public ModuleController(ModuleService moduleService) {
        this.moduleService = moduleService;
    }

    /**
     * 查询分页数据
     */
    @ApiOperation(value = "查询分页数据")
    @PostMapping(value = "/getList")
    public ResponseBean<PageInfo<Module>> getList(@RequestBody QueryPage<Module> page) {

        return new ResponseBean<>(moduleService.list(page));
    }

    /**
     * 根据id查询
     */
    @ApiOperation(value = "根据id查询数据")
    @GetMapping(value = "/getById")
    public ResponseBean<Module> getById(@RequestParam("id") Serializable id) {
        return new ResponseBean<>(moduleService.getById(id));
    }

    /**
     * 新增
     */
    @ApiOperation(value = "新增/修改 数据")
    @PostMapping(value = "/saveUpdate")
    public ResponseBean<Boolean> saveUpdate(@RequestBody Module module) {
        return new ResponseBean<>(moduleService.saveOrUpdate(module));
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除数据")
    @DeleteMapping(value = "/del")
    public ResponseBean<Boolean> delete(@RequestParam("id") Serializable id) {
        return new ResponseBean<>(moduleService.removeById(id));
    }
}
